// pages/demandDetail/demandDetail.js

var api = require('../../utils/api.js');


Page({

  /**
   * 页面的初始数据
   */
  data: {
    isIpx: api.isIpx ? true : false,
    comment_value:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let did = options.did,that = this;
    this.setData({
      options: options,
      userbaseinfo: api.getStorageData().userbaseinfo,
    });

    api.post({
      url: 'Demand/detailed',
      data: {
        token: that.data.userbaseinfo.token,
        did: did
      },
      success: function (data) {
        if (data.code == 200) {
          let _data = data.data;
          that.setData({
            demand_data: _data
          });

        }

      }
    });
  },

  commentSubmit: function(e){
    let that = this;
    api.post({
      url: 'Demand/addComment',
      data: e.detail.value,
      success: function (data) {
        if (data.code == 200) {
          wx.showToast({
            title: data.data.message,
            icon: 'success',
            mask:true
          });
          let data_temp = {
            avatar: that.data.userbaseinfo.data.avatar,
            cid:'-1',
            createtime:'刚刚',
            nickname: that.data.userbaseinfo.data.nickname,
            content: data.content.content
          };
          that.data.demand_data.comment.unshift(data_temp);
          let demand_data = that.data.demand_data.comment;
          that.setData({
            comment_value:'',
            'demand_data.comment': demand_data
          });
        }
      }
    });


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})